﻿CREATE PROCEDURE [dbo].[JobInsert]
(@JobID UniqueIdentifier,
@RunID UniqueIdentifier,
@ComponentID UniqueIdentifier,
@Dependency varchar(500),
@IsFirstJob bit,
@IsLastJob bit,
@HasError bit,
@Cancelled bit,
@Priority int,
@SubmitTime datetime,
@ReceiveTime datetime,
@StartTime datetime,
@FinishTime datetime)
AS begin
	if exists (select * from Job where JobID=@JobID) begin
		update Job set
			RunID=@RunID,
			ComponentID=@ComponentID,
			Dependency=@Dependency,
			IsFirstJob=@IsFirstJob,
			IsLastJob=@IsLastJob,
			HasError=@HasError,
			Cancelled=@Cancelled,
			Priority=@Priority,
			SubmitTime=@SubmitTime,
			ReceiveTime=@ReceiveTime,
			StartTime=@StartTime,
			FinishTime=@FinishTime
		where
			JobID=@JobID;
	end
	else begin
		insert into Job (
			JobID,
			RunID,
			ComponentID,
			Dependency,
			IsFirstJob,
			IsLastJob,
			HasError,
			Cancelled,
			Priority,
			SubmitTime,
			ReceiveTime,
			StartTime,
			FinishTime) 
		values (
			@JobID,
			@RunID,
			@ComponentID,
			@Dependency,
			@IsFirstJob,
			@IsLastJob,
			@HasError,
			@Cancelled,
			@Priority,
			@SubmitTime,
			@ReceiveTime,
			@StartTime,
			@FinishTime);
	end
end